package faktorI;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


import javax.imageio.ImageIO;
import javax.swing.JTextArea;

public class JTAWithBackgroundImage extends JTextArea
{
  private final BufferedImage bufferedImage;
  private final TexturePaint texturePaint;

  public JTAWithBackgroundImage(File file) throws IOException
  {
    super();
    bufferedImage = ImageIO.read(file);
    Rectangle rect = new Rectangle(0, 0, bufferedImage.getWidth(null), bufferedImage.getHeight(null));
    texturePaint = new TexturePaint(bufferedImage, rect);
    setOpaque(false);
  }

  /**
   * Override the painComponent method to do our image drawing.
   */
  public void paintComponent(Graphics g)
  {
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(texturePaint);
    g.fillRect(0, 0, getWidth(), getHeight());
    super.paintComponent(g);
  }
}

